package cn.iocoder.yudao.module.product.controller.admin.sku;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 商品 SKU")
@RestController
@RequestMapping("/product/sku")
@Validated
public class ProductSkuController {
    @Resource
    private ProductSkuService productSkuService;
    @GetMapping("/crm/sku/list")
    @Operation(summary = "获得sku列表")
    //@PreAuthorize("@ss.hasPermission('trade:order:sku:query')")
    public CommonResult<List<ProductSkuRespVO>> getSkuList(){
        return success(ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkuList()));
    }


    @GetMapping("/list")
    @Operation(summary = "获得商品 sku 列表")
    @Parameter(name = "spuId", description = "sku 编号列表", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('product:sku:list')")
    public CommonResult<List<ProductSkuRespVO>> getSpuList(@RequestParam("spuId") Long spuId) {
        return success(productSkuService.findSkuListBySpuId(spuId));
    }

    @GetMapping("/containerList")
    @Operation(summary = "获得商品使用容器列表")
    @PreAuthorize("@ss.hasPermission('product:sku:containerList')")
    public CommonResult<List<ProductSkuRespVO>> getContainerList() {
        return success(productSkuService.getContainerList());
    }
}
